package com.atguigu.config.condition;

import com.atguigu.bean.RainBow;
import org.springframework.beans.factory.support.BeanDefinitionRegistry;
import org.springframework.beans.factory.support.BeanNameGenerator;
import org.springframework.beans.factory.support.RootBeanDefinition;
import org.springframework.context.annotation.ImportBeanDefinitionRegistrar;
import org.springframework.core.type.AnnotationMetadata;

public class MyImportBeanDefinitionRegistrar implements ImportBeanDefinitionRegistrar {

    /**
     * AnnotationMetadata 当前类的注解信息
     * BeanDefinitionRegistry Bean定义的注册类，需要注册的bean通过registerBeanDefinition手工注册
     */
    public void registerBeanDefinitions(AnnotationMetadata importingClassMetadata,
                                        BeanDefinitionRegistry registry) {
        boolean beanDefinitionRed = registry.containsBeanDefinition("com.atguigu.bean.Red");
        boolean beanDefinitionBlue = registry.containsBeanDefinition("com.atguigu.bean.Blue");
        if (beanDefinitionBlue && beanDefinitionRed) {
            registry.registerBeanDefinition("rainBow", new RootBeanDefinition(RainBow.class));
        }
    }


}
